<?php
/*! \brief
 * This is the WFConfig class major purpose for setting WidgetFramework config
 * \author William Su
 */
class WFConfig
{
    private static $instance;
    /**
     * @var WF
     */
    private $objFramework;
    public function __construct($objFramework){
        $this->objFramework = $objFramework;
        if($this->objFramework->isUnitTest()){
            $wfconf_dbconfig["dbname"] = "tmwf_test";
            $wfconf_dbconfig["dbfile"] = dirname(__FILE__) . "/../../../repository/db/sqlite/tmwf_test.db";
        }
        global $wfconf_dbconfig, $wfconf_version, $wfconf_shownew_days, $wfconf_base;
        if(!(isset($wfconf_dbconfig) && isset($wfconf_version) && 
              isset($wfconf_shownew_days) && isset($wfconf_base) &&
              isset($wfconf_dir_lang))){
              require dirname(__FILE__) . '/../../config.php';
        }
        self::$instance['wfconf_dbconfig'] = $wfconf_dbconfig;
        self::$instance['wfconf_version'] = $wfconf_version;
        self::$instance['wfconf_shownew_days'] = $wfconf_shownew_days;
        self::$instance['wfconf_base'] = $wfconf_base;
        self::$instance['wfconf_dir_lang'] = $wfconf_dir_lang;
        //$GLOBALS['wfconf_debug'] = "true";
        ////self::$instance['wfconf_debug_level'] = $GLOBALS['wfconf_debug_level'];
        self::$instance['wfconf_debug_type'] = $GLOBALS['wfconf_debug_type'];
        self::$instance['wfconf_debug_dir'] = $GLOBALS['wfconf_debug_dir'];
        self::$instance['wfconf_debug_logname'] = $GLOBALS['wfconf_debug_logname'];
        self::$instance['wfconf_debug_size'] = $GLOBALS['wfconf_debug_size'];
        self::$instance['wfconf_debug_backup'] = $GLOBALS['wfconf_debug_backup'];
        self::$instance['wfconf_upgradeWF_debug_logname'] = $GLOBALS['wfconf_upgradeWF_debug_logname'];
        self::$instance['wfconf_client_debug_level'] = $GLOBALS['wfconf_client_debug_level'];
        self::$instance['wfconf_client_debug_type'] = $GLOBALS['wfconf_client_debug_type'];
        self::$instance['wfconf_client_debug_dir'] = $GLOBALS['wfconf_client_debug_dir'];
        self::$instance['wfconf_client_debug_logname'] = $GLOBALS['wfconf_client_debug_logname'];
        self::$instance['wfconf_client_debug_size'] = $GLOBALS['wfconf_client_debug_size'];
        self::$instance['wfconf_client_debug_backup'] = $GLOBALS['wfconf_client_debug_backup'];
        self::$instance['wp_max_execution_time'] = $GLOBALS['wp_max_execution_time'];
    }
    public function getDebugLevel(){
        ////$ret = self::$instance['wfconf_debug_level'];
        switch($GLOBALS['wfconf_debug']){
            case true:
                $ret = "DEBUG";
                break;
            default:
                $ret = "INFO";
                break;
        }
        return $ret;
    }
    public function getDebugType(){
        $ret = self::$instance['wfconf_debug_type'];
        return $ret;
    }
    public function getWpMaxExecutionTime(){
        $ret = self::$instance['wp_max_execution_time'];
        return $ret;
    }
    public function getDebugDir(){
        $ret = self::$instance['wfconf_debug_dir'];
        return $ret;
    }
    public function getDebugLogname(){
        $ret = self::$instance['wfconf_debug_logname'];
        return $ret;
    }
    public function getUpgradeWFDebugLogname(){
        $ret = self::$instance['wfconf_upgradeWF_debug_logname'];
        return $ret;
    }
    public function getDebugSize(){
        $ret = self::$instance['wfconf_debug_size'];
        return $ret;
    }
    public function getDebugBackup(){
        $ret = self::$instance['wfconf_debug_backup'];
        return $ret;
    }
    public function getClientDebugLevel(){
        $ret = self::$instance['wfconf_client_debug_level'];
        return $ret;
    }
    public function getClientDebugType(){
        $ret = self::$instance['wfconf_client_debug_type'];
        return $ret;
    }
    public function getClientDebugDir(){
        $ret = self::$instance['wfconf_client_debug_dir'];
        return $ret;
    }
    public function getClientDebugLogname(){
        $ret = self::$instance['wfconf_client_debug_logname'];
        return $ret;
    }
    public function getClientDebugSize(){
        $ret = self::$instance['wfconf_client_debug_size'];
        return $ret;
    }
    public function getClientDebugBackup(){
        $ret = self::$instance['wfconf_client_debug_backup'];
        return $ret;
    }
    public function getShownewDays(){
        $ret = self::$instance['wfconf_shownew_days'];
        return $ret;
    }
    public function getDbConfigType(){
        $ret = self::$instance['wfconf_dbconfig']['type'];
        return $ret;
    }
    public function getDbConfigHost(){
        $ret = self::$instance['wfconf_dbconfig']['host'];
        return $ret;
    }
    public function getDbConfigDbname(){
        $ret = self::$instance['wfconf_dbconfig']['dbname'];
        return $ret;
    }
    public function getDbConfigUsername(){
        $ret = self::$instance['wfconf_dbconfig']['username'];
        return $ret;
    }
    public function getDbConfigPassword(){
        $ret = self::$instance['wfconf_dbconfig']['password'];
        return $ret;
    }
    public function getDbConfigDbfile(){
        $ret = self::$instance['wfconf_dbconfig']['dbfile'];
        return $ret;
    }
    public function getDbConfig(){
        $ret = self::$instance['wfconf_dbconfig'];
        return $ret;
    }
    public function getVersion(){
        $ret = self::$instance['wfconf_version'];
        return $ret;
    }
    public function getBase(){
        $ret = self::$instance['wfconf_base'];
        return $ret;
    }
    public function getDirLang(){
        $ret = self::$instance['wfconf_dir_lang'];
        return $ret;
    }
    public function getCurrentLang(){
        $ret = 'en_US'; //default
        if(isset($_COOKIE['LANG']) && $_COOKIE['LANG']){
            $ret = $_COOKIE['LANG'];
        }
        return $ret;
    }
    public function getHttpProtocal(){
    	$ret = "http://"; //default
        if(isset($_SERVER['HTTPS'])){
	        if($_SERVER['HTTPS'] == "off"){
		        $ret = "http://";
	        }else{
		        $ret = "https://";
	        }
		}
        return $ret;
    }
    public function getHttpHost(){
    	$ret = '127.0.0.1'; //default
        if(isset($_SERVER['HTTP_HOST'])){
	        $ret = $_SERVER['HTTP_HOST'];
		}
        return $ret;
    }
}
